package com.chuan.jms.cosumer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by zhaowenchuan on 2018/11/1.
 */
public class GenerateThreadPool {

    private final static Integer CORE_THREAD = 5;

    private final static Integer MAX_THREAD = 10;

    private final static Long TIME = 2L;

    private final static ArrayBlockingQueue<Runnable> blokingQueue
            = new ArrayBlockingQueue<Runnable>(6);   //阻塞队列

    private static ExecutorService executorService;

    public static ExecutorService generatePool() {
        return ((null != executorService)) ? executorService :
            new ThreadPoolExecutor(CORE_THREAD,
                MAX_THREAD,
                TIME,
                TimeUnit.SECONDS,
                blokingQueue,
                new ThreadPoolExecutor.DiscardOldestPolicy());
    }
}
